package sdk.servlet;

import hjj.service.DeptManager;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sdk.service.DutyManager;
import sdk.service.EduDegreeManager;
import sdk.service.EducationManager;
import sdk.service.EmpManager;
import sdk.service.EmpStatusManager;
import sdk.service.JobTitleManager;
import sdk.service.SkillGradeManager;

import lgq.service.TrainManager;
import lgq.service.TrainPropertyManager;
import lgq.service.TrainTypeManager;
import lgq.service.TrainWayManager;
import model.Emp;
import model.Train;

public class UpdateEmpServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		Emp emp = new Emp();
		emp.setId(Integer.parseInt(request.getParameter("id")));
		emp.setName(request.getParameter("empname"));
		emp.setSex(request.getParameter("sex"));
		emp.setPhoto(request.getParameter("photo"));
		emp.setIdCardid(request.getParameter("idcardid"));
		emp.setEducationimg(request.getParameter("educationimg"));
		emp.setSalary(Double.parseDouble(request.getParameter("salary")));
		emp.setAddress(request.getParameter("address"));
		emp.setPhone(request.getParameter("phone"));
		emp.setEmpno(request.getParameter("empno"));
		
		DeptManager dm = new DeptManager();		
		emp.setDept(dm.getDeptByName(request.getParameter("deptname")));
		
		EducationManager ecm = new EducationManager();
		emp.setEducation(ecm.getById(Integer.parseInt(request.getParameter("education"))));
		
		EduDegreeManager edm = new EduDegreeManager();
		emp.setEduDegree(edm.getById(Integer.parseInt(request.getParameter("edudegree"))));
		
		DutyManager dum = new DutyManager();
		emp.setDuty(dum.getDutyById(Integer.parseInt(request.getParameter("dutyid"))));
		
		JobTitleManager jtm = new JobTitleManager();
		emp.setJobTitle(jtm.getById(Integer.parseInt(request.getParameter("jobtitle"))));
		
		EmpStatusManager esm = new EmpStatusManager();
		emp.setEmpStatus(esm.getEmpStatusById(Integer.parseInt(request.getParameter("empstatus"))));
		
		SkillGradeManager sgm = new SkillGradeManager();
		emp.setSkillGrade(sgm.getById(Integer.parseInt(request.getParameter("skillgrade"))));
		
		
		EmpManager em=new EmpManager();
		em.updateEmp(emp);
		request.getRequestDispatcher("/FindEmpServlet").forward(request,response);
	}

}
